/*
 * background tasks
 */
var tasks_content;
var tasks_tab;
var tasks_tasks;

function tasks_init() {
	tasks_content = document.getElementById("tasks_content");
	tasks_tab = main_createTab("tasks_content", _T("Tasks"));
	main_contents.push(tasks_content);
	tasks_tasks = new Array();
}

function tasks_close(_index) {
	tasks_content.removeChild(tasks_tasks[_index].listDiv);
	tasks_tasks[_index] = null;
}

function tasks_Task(_name, _count) {
	var _index = tasks_tasks.length;
	tasks_tasks[_index] = this;
	this.listDiv = document.createElement("div");
	this.popupDiv = document.createElement("div");
	this.fieldset = document.createElement("fieldset");
	this.legend = document.createElement("legend");
	this.legend.appendChild(document.createTextNode(_name));
	this.bClose = document.createElement("div");
	this.bClose.setAttribute("style",
			"position: absolute; top: 0px; right: 0px;");
	this.bClose.className = "button";
	this.bClose.title = _T("Close");
	this.bClose.setAttribute("onClick", "tasks_close(" + _index + ")");
	this.bClose.appendChild(document.createTextNode("X"));
	this.room = document.createElement("div");
	this.listDesc = document.createElement("div");
	this.listDesc.setAttribute("class", "caption");
	this.listDesc.setAttribute("align", "right");
	this.listDesc.textContent=_T("Unknown");
	this.popupDesc = document.createElement("div");
	this.popupDesc.setAttribute("class", "caption");
	this.popupDesc.setAttribute("align", "right");
	this.popupDesc.textContent=_T("Unknown");
	this.fieldset.appendChild(this.legend);
	this.fieldset.appendChild(this.bClose);
	this.listBars = new Array();
	this.popupBars = new Array();
	for ( var i = 0; i < _count; i++) {
		//list bars
		var bar = document.createElement("canvas", false);
		bar.setAttribute("height", "10px");
		bar.setAttribute("width", (contentWidth - 20) + "px");
		this.fieldset.appendChild(bar);
		this.listBars.push(new ProgressBar(bar));
		//popup bars
		bar = document.createElement("canvas", false);
		bar.setAttribute("height", "10px");
		bar.setAttribute("width", (contentWidth - 50) + "px");
		this.popupDiv.appendChild(bar);
		this.popupBars.push(new ProgressBar(bar));
	}
	this.fieldset.appendChild(this.listDesc);
	this.listDiv.appendChild(this.fieldset);
	this.popupDiv.appendChild(this.popupDesc);
	tasks_content.insertBefore(this.listDiv, tasks_content.firstChild);
	popup_show(_T("WorkingDots"),this.popupDiv,"task_"+_index,(contentWidth-30)+"px");

	this.update = function(_progress, _desc) {
		this.updateMessage(_desc);
		for ( var i = 0; i < this.listBars.length; i++) {
			this.listBars[i].draw(_progress[i][0], _progress[i][1]);
		}
		for ( var i = 0; i < this.popupBars.length; i++) {
			this.popupBars[i].draw(_progress[i][0], _progress[i][1]);
		}
	};
	this.updateMessage = function(_desc) {
		this.listDesc.innerHTML = _desc;
		this.popupDesc.innerHTML = _desc;
	};
}